package com.tehui.view;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.View;
import android.widget.Button;

import com.tehui.R;

/**
 * Created by jasmine on 2017/5/23.
 */

public class DownLoadDialog extends Dialog {

    private HorizontalProgressBarWithNumber mProgressBar;

    public DownLoadDialog(@NonNull Context context) {
        super(context, R.style.NobackDialog_two);
    }

    private Button no;//取消按钮

    private onNoOnclickListener noOnclickListener;//取消按钮被点击了的监听器

    /**
     * 设置取消按钮的显示内容和监听
     * @param onNoOnclickListener
     */
    public void setNoOnclickListener(onNoOnclickListener onNoOnclickListener) {
        this.noOnclickListener = onNoOnclickListener;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.download_dialog_layout);
        //按空白处不能取消动画
        setCanceledOnTouchOutside(false);
        //初始化界面控件
        initView();
        //初始化界面控件的事件
        initEvent();
    }

    /**
     * 初始化界面的确定和取消监听器
     */
    private void initEvent() {
        //设置取消按钮被点击后，向外界提供监听
        no.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (noOnclickListener != null) {
                    noOnclickListener.onNoClick();
                }
            }
        });
    }

    /**
     * 初始化界面控件
     */
    private void initView() {
        no = (Button) findViewById(R.id.no);
        mProgressBar = (HorizontalProgressBarWithNumber) findViewById(R.id.progressbar);
    }

    public interface onNoOnclickListener {
        void onNoClick();
    }

    public void setProgressNum(int progress) {
        mProgressBar.setProgress(progress);
    }
}
